package com.ifly.service;

import com.ifly.dao.EmpDAO;
import com.ifly.entity.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class EmpServiceImpl implements EmpService{
    @Autowired
    private EmpDAO empDAO;

    //添加员工信息
    @Override
    //事务的属性是传播的，没必要每次都开启事务
    @Transactional(propagation = Propagation.SUPPORTS)
    public void add(Emp emp) {
        emp.setId(UUID.randomUUID().toString());
        empDAO.add(emp);
    }

    //删除员工信息
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public void delete(String id) {
        empDAO.delete(id);
    }

    //查询所有员工信息
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Emp> findAll() {
        return empDAO.findAll();
    }

    //根据id查询员工信息
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Emp findById(String id) {
        return empDAO.findById(id);
    }

    //更新员工信息
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public void update(Emp emp) {
        empDAO.update(emp);
    }
}
